home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / Testing & Debugging / Debuggers & dcmds / MacsBug 6.5d9 / dcmds / C Samples / Vol.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-26  |  4.8 KB  |  209 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Vol.c
  3.  
  4.     Contains:    This is the Vol dcmd.
  5.  
  6.     Written by:    Scott Douglas, Dave Lyons.
  7.  
  8.     Copyright:    © 1988,1993-1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <4>   24-Jan-94    JM3        EqualString is now in TextUtils.h with the Universal Interfaces.
  13.          <2>     9/10/93    DAL        Fixed volume-name matching to work again (was using
  14.                                     non-prototyped "EQUALSTRING" instead of EqualString).  Widened
  15.                                     the volume-name column.  Changed "VCB at" to "VCB addr" and made
  16.                                     it align for 32-bit addresses.
  17.  
  18.     Modification history:
  19.         29Nov88 sad        revised for new dcmd names.  display more info.
  20.          5Oct88 sad        written.
  21.  
  22.     The following MPW commands will build the dcmd and copy it to the
  23.     "Debugger Prefs" file in the System folder. The dcmd's name in
  24.     MacsBug will be the name of the file built by the Linker.
  25.     You must first copy dcmd.h, dcmdGlue.a.o and DRunTime.o from the
  26.     C Samples folder into this folder.
  27.  
  28.     C Put.c
  29.     C Vol.c
  30.     Link dcmdGlue.a.o Vol.c.o put.c.o DRuntime.o "{Libraries}"Interface.o -o Vol
  31.     BuildDcmd Vol 1002
  32.     Echo 'include "Vol";'    |    Rez -a -o "{systemFolder}Debugger Prefs"
  33. */
  34.  
  35. #include <Types.h>
  36. #include <Memory.h>
  37. #include <OSUtils.h>
  38. #include <Files.h>
  39. #include <TextUtils.h>
  40.  
  41. #include "dcmd.h"
  42. #include "put.h"
  43.  
  44. #define VCBQHdr ((QHdrPtr)0x356)
  45.  
  46.  
  47. static void DrawHdr()
  48. {
  49. //                             1         2         3         4         5         6         7
  50. //                    1234567890123456789012345678901234567890123456789012345678901234567890123456789
  51.     dcmdDrawLine("\pvRef Vol                  Flg dRef Drive FSID #Blk BlkSiz #Files #Dirs  Blsd Dir VCB addr");
  52. }
  53.  
  54.  
  55. static void DrawVCB(VCB* vcbp)
  56. {
  57.     PutUHexWord(vcbp->vcbVRefNum);
  58.     PutSpace();
  59.     PutPStrTruncTo(vcbp->vcbVN,15+10);
  60.     PutSpace();
  61.     PutChar((vcbp->vcbFlags & 0x8000) ? 'D' : 'd');
  62.     PutChar((vcbp->vcbAtrb & 0x8000) ? 'S' : 's');
  63.     PutChar((vcbp->vcbAtrb & 0x4000) ? 'H' : 'h');
  64.     PutSpace();
  65.     PutUHexWord(vcbp->vcbDRefNum);
  66.     PutSpace();
  67.     PutSpace();
  68.     PutUHexWord(vcbp->vcbDrvNum);
  69.     PutSpace();
  70.     PutUHexWord(vcbp->vcbFSID);
  71.     PutSpace();
  72.     PutUHexWord(vcbp->vcbNmAlBlks);
  73.     PutSpace();
  74.     PutUHexZTo(vcbp->vcbAlBlkSiz,6,47+10);
  75.     PutSpace();
  76.     PutUHexZTo(vcbp->vcbFilCnt,6,54+10);
  77.     PutSpace();
  78.     PutUHexZTo(vcbp->vcbDirCnt,6,61+10);
  79.     PutSpace();
  80.     PutUHexZTo(vcbp->vcbFndrInfo[0],6,70+10);
  81.     PutSpace();
  82.     PutUHexZTo((unsigned long)vcbp,8,77+10);
  83.     PutLine();
  84. }
  85.  
  86.  
  87. // PrefixPStr
  88. //
  89. // Returns true if astr is equal to a prefix of bstr.
  90. // astr must not be longer than 31 characters.
  91.  
  92. static Boolean PrefixPStr(const Str255 astr, const Str255 bstr)
  93. {
  94.     char newstr[32];
  95.     int alen = *astr;
  96.     int blen = *bstr;
  97.  
  98.     if (alen <= blen)
  99.       {
  100.         BlockMove(bstr+1,newstr+1,alen);
  101.         newstr[0] = alen;
  102.         return EqualString(astr,newstr,false,true);
  103.       }
  104.  
  105.     return false;    
  106. }
  107.  
  108.  
  109.  
  110. pascal void CommandEntry(dcmdBlock* paramPtr)
  111. {
  112.     switch (paramPtr->request)
  113.       {
  114.         case dcmdInit:
  115.             break;
  116.  
  117.         case dcmdHelp:
  118.             dcmdDrawLine("\pvol [vRefNum|drvNum|\"vol name\"]");
  119.             dcmdDrawLine("\p   Displays volume information for the given vrefnum, volume name or all mounted volumes.");
  120.             dcmdDrawLine("\p      Flags are D/d=Dirty, S/s=Software locked, H/h=Hardware locked.");
  121.             break;
  122.  
  123.         case dcmdDoIt:
  124.           {
  125.             Boolean doOneVCB = false;
  126.             long vref;
  127.             short c;
  128.             Boolean haveVolName = false;
  129.             Str255 volname;
  130.             VCB* vcbp;
  131.             int numvcbs = 0;
  132.             Boolean foundOne = false;
  133.  
  134.             dcmdSwapWorlds();
  135.  
  136.             dcmdDrawLine("\pDisplaying Volume Control Blocks");
  137.  
  138.             // get low-memory values after dcmdSwapWorlds()
  139.             vcbp = (VCB*) (VCBQHdr->qHead);
  140.  
  141.             c = dcmdPeekAtNextChar();
  142.             if (c == '"' || c == '\'')
  143.               {
  144.                 haveVolName = true;
  145.                 (void) dcmdGetNextParameter(volname);
  146.               }
  147.             else
  148.                 (void) dcmdGetNextExpression(&vref, &doOneVCB);
  149.  
  150.             if (doOneVCB)
  151.                 vref = (short) vref;
  152.  
  153.             while (vcbp)
  154.               {
  155.                 if ((doOneVCB && (vcbp->vcbVRefNum == vref || vcbp->vcbDrvNum == vref)) ||
  156.                     (haveVolName && PrefixPStr(volname,vcbp->vcbVN)) ||
  157.                     (!doOneVCB && !haveVolName))
  158.                   {
  159.                     numvcbs++;
  160.                     if (!foundOne)
  161.                       {
  162.                         DrawHdr();
  163.                         foundOne = true;
  164.                       }
  165.                     DrawVCB(vcbp);
  166.                   }
  167.                 if (paramPtr->aborted) break;
  168.                 if (vcbp->qLink == 0)
  169.                     if (vcbp != (VCB*)(VCBQHdr->qTail))
  170.                         dcmdDrawLine("\pVCB queue does not end at VCBQHdr.qTail");
  171.                 vcbp = (VCB*)vcbp->qLink;
  172.               }
  173.             if (!paramPtr->aborted)
  174.                 if (haveVolName || doOneVCB)
  175.                   {
  176.                     if (!foundOne)
  177.                         if (haveVolName)
  178.                           {
  179.                             PutPStr("\pNo mounted volumes match \"");
  180.                             PutPStr(volname);
  181.                             PutChar('"');
  182.                             PutLine();
  183.                           }
  184.                         else
  185.                           {
  186.                             PutPStr("\pNo mounted volumes match ");
  187.                             PutUHexWord(vref);
  188.                             PutLine();
  189.                           }
  190.                   }
  191.                 else
  192.                   {
  193.                     PutUDec(numvcbs);
  194.                     PutPStr("\p VCBs");
  195.                     PutLine();
  196.                   }
  197.  
  198.             dcmdSwapWorlds();
  199.             break;
  200.           }
  201.  
  202.         default:
  203.             PutPStr("\punknown request ");
  204.             PutUDec(paramPtr->request);
  205.             PutLine();
  206.             break;
  207.       }
  208. } // CommandEntry
  209.